﻿CREATE PROCEDURE [dbo].[s_ExportFromMegasys_Bulk]
AS
SET IMPLICIT_TRANSACTIONS OFF
SET NOCOUNT ON
DECLARE curEFM CURSOR
READ_ONLY FOR
SELECT v_ExportFromMegasys.XFA_CLASSACCOUNT
FROM        AutoBank_Prod.megasys.FA_ccccACCT v_ExportFromMegasys LEFT OUTER JOIN
                      t_Loan ON v_ExportFromMegasys.XFA_CLASS = t_Loan.Ms_CLASS AND v_ExportFromMegasys.XFA_ACCOUNT = t_Loan.Ms_ACCOUNT
WHERE (v_ExportFromMegasys.XFA_ASTATUS = N'A') AND
			(t_Loan.MsID IS NULL) AND
			(dbo.VinCheck(v_ExportFromMegasys.XFA_VIN) = 1)
			--AND	(XFA_OPENDT_RAW >= '01/01/2006')
ORDER BY v_ExportFromMegasys.XFA_OPENDT

DECLARE @MsID varchar(40),@LoanID int
OPEN curEFM

FETCH NEXT FROM curEFM INTO @MsID
WHILE @@fetch_status = 0 BEGIN
	PRINT @MsID + ' <> s_ExportFromMegasys_Bulk'
	SET @MsID = LEFT(@MsID,3)+'-'+RIGHT(@MsID,6)
	EXEC s_ExportFromMegasys @MsID
	IF dbo.Stop() = 1 BREAK
	FETCH NEXT FROM curEFM INTO @MsID
END

CLOSE curEFM
DEALLOCATE curEFM


